<?php 
	class Newses extends CI_Model{

		function __construct(){
			parent::__construct();
		}

		function get_category(){
			$sql = "SELECT id, name, pid FROM {$this->db->dbprefix}news_categorys ORDER BY sort DESC";
			$result = $this->db->query($sql)->result_array();
			return $result;
		}

		function get_news_by_category($category_id = 0){
			$sql = "SELECT id, title, content, add_time FROM aws_article WHERE category_id=$category_id LIMIT 5";
			$result = $this->db->query($sql)->result_array();
			return $result;
		}

		function get_news10($school_id, $limit = 10){
			$sql = "SELECT id, title, content FROM {$this->db->dbprefix}news WHERE school_id = $school_id OR school_id = 0 ORDER BY add_time DESC LIMIT $limit";
			$result = $this->db->query($sql)->result_array();
			return $result;
		}

		function get_question10($limit = 10){
			$sql = "SELECT question_id, question_content, question_detail FROM aws_question ORDER BY add_time DESC LIMIT $limit";
			$result = $this->db->query($sql)->result_array();
			return $result;
		}

		function get_news_list($limit = 0, $offset = 0, $conditions = array()){
			$where = "status = 1";
	      	if(!empty($conditions['school_id'])) $where .= " AND (school_id = '{$conditions['school_id']}' )";
	      	if(!empty($conditions['category_id'])) $where .= " AND (top_category_id = '{$conditions['category_id']}' OR category_id = '{$conditions['category_id']}')";
			$sql = "SELECT SQL_CALC_FOUND_ROWS * FROM {$this->db->dbprefix}news WHERE $where ORDER BY id DESC LIMIT $limit, $offset";
			$result = $this->db->query($sql)->result_array();
			$row_num =  $this->db->query('SELECT FOUND_ROWS() as row_num;')->row_array();
			return array("count" => $row_num['row_num'], "result" => $result);
		}
	}